﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DIProject.Sales
{
    public partial class CashPaid : System.Windows.Forms.Form// Form
    {
        public CashPaid()
        {
            InitializeComponent();
            numericUpDownPaid.Minimum = decimal.Zero;
            numericUpDownPaid.Maximum = decimal.MaxValue;
        }

        private void CashPaid_Shown(object sender, EventArgs e)
        {
            numericUpDownPaid.Focus();
            string str = numericUpDownPaid.Value.ToString();
            numericUpDownPaid.Select(0, str.Length);

        }
        public byte Discount
        {
            get
            {
                object obj = cbDiscounts.SelectedValue;
                if (obj == null)
                    return 0;
                return (byte)obj;
            }
        }
       
        public Util.TypePayment Payment
        {
            get
            {
                object obj = cbTypePayment.SelectedValue;
                if (obj == null)
                    return DIProject.Util.TypePayment.CASH;
                return (DIProject.Util.TypePayment)obj;
            }
        }
        private void CashPaid_Load(object sender, EventArgs e)
        {
            Util.Discount.Common disc = new DIProject.Util.Discount.Common();
            cbDiscounts.DataSource = disc.Discounts;
            cbDiscounts.SelectedIndex = 0;
            if (cbDiscounts.Items.Count == 1)
                cbDiscounts.Enabled = false;
            else
                cbDiscounts.Enabled = true;
            Util.Payments.Common pay = new DIProject.Util.Payments.Common();
           /* DataTable dt = new DataTable();
            dt.Columns.Add("Key", typeof(Int32));
            dt.Columns.Add("Value", typeof(string));
            for (Int32 i = 0; i<)
            {
            DataRow dr = dt.NewRow();
            dr["Key"] = p.Key;
            dr["Value"] = p.Value;
            dt.Rows.Add(dr);
                }*/
            cbTypePayment.DataSource = pay.Payments;
            if (cbTypePayment.Items.Count == 1)
                cbTypePayment.Enabled = false;
            else
                cbTypePayment.Enabled = true;
        }
        
        private void CashPaid_KeyDown(object sender, KeyEventArgs e)
        {
            /*
            //клавиша вверх
            if (e.KeyCode == Keys.Up)
            {
                Int32 count = cbDiscounts.Items.Count;
                if (count == 1)
                    return;
                Int32 selInd = cbDiscounts.SelectedIndex;
                if (selInd == 0)
                    return;
                cbDiscounts.SelectedIndex -= 1;
            }
            //клавиша вниз
            if (e.KeyCode == Keys.Down)
            {
                Int32 count = cbDiscounts.Items.Count;
                if (count == 1)
                    return;
                Int32 selInd = cbDiscounts.SelectedIndex;
                if (selInd == (count - 1))
                    return;
                cbDiscounts.SelectedIndex += 1;
            }
        numericUpDownPaid.Focus();
        numericUpDownPaid.Select(0, numericUpDownPaid.Value.ToString().Length);*/
        }

        private void cbTypePayment_SelectedIndexChanged(object sender, EventArgs e)
            {

            }

        private void button1_Click(object sender, EventArgs e)
            {
            DialogResult dr = MessageBox.Show("Отменить чек?", "Отмена", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (dr == DialogResult.OK)
            {
            this.DialogResult = DialogResult.Cancel;
                }
            }
    }
}